package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.domain.inst.repository.SceneInstRepository;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInst;
import com.iwhalecloud.bss.kite.service.attr.data.CustAttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Objects;

/**
 * 延期产品服务期限
 * Created by jinchunyu on 2021/5/15 10:47
 */
public class ExtendedPeriodAttrHandler extends AbstractAttrHandler<KiteInst, CustAttrData> {

    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Autowired
    private IOperateSceneInstService operateSceneInstService;

    @Override
    public void after(KiteAttr attr, KiteInst inst, CustAttrData data) {
        //产品变更 延期分组置灰
        if (KiteStringUtils.isEqual(data.getServiceOfferId(), "2826")
            && KiteStringUtils.isEqual(attr.getGroupId(), "300000173")) {
            attr.setIsEdit(KeyConsts.IFTRUE_F);
            operateSceneInstService
                .setAttr(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), attr);
        }
        // 雁飞自研烟感管理平台
        KiteOfferInst mainOfferInst = querySceneInstService.getMainOfferInstByProdInstId(data.getCustId(), inst.getInstId());
        if (Objects.nonNull(mainOfferInst) && KiteStringUtils.equals(mainOfferInst.getOfferId(), "50040948") && KiteStringUtils.equals(inst.getSpecId(), "50000020")) {
            attr.setAttrId("2021030702");
            attr.setAttrValues(SceneInstRepository.getKiteAttrValues(attr));
        }
        super.after(attr, inst, data);
    }
}
